package javaguide.并发;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

public class MultiThread {
    public static void main(String[] args) {

        //获取线程管理MXBean
        ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
        //不需要获取同步的 monitor 和 synchronizer 信息，仅获取线程和线程堆栈信息
        ThreadInfo[] threadInfos = mxBean.dumpAllThreads(false, false);
        //遍历线程信息，仅打印线程 ID 和线程名称信息
        for (ThreadInfo threadInfo:
             threadInfos) {
            System.out.println("[" + threadInfo.getThreadId() + "] " + threadInfo.getThreadName());

        }

    }
}
